package com.zwj.user.controller.user;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zwj.common.R;
import com.zwj.common.entity.AuditAdministrator;
import com.zwj.common.entity.SuperAdministrator;
import com.zwj.common.entity.User;
import com.zwj.user.entity.UserAndRole;
import com.zwj.user.entity.UserId;
import com.zwj.user.security.PasswordSecurity;
import com.zwj.user.service.SuperAdministratorService;
import com.zwj.user.service.UserAndRoleService;
import com.zwj.user.service.UserIdService;
import javafx.scene.canvas.GraphicsContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@Slf4j
@RequestMapping("/superAdministrator")
public class SuperAdministratorController {

    @Resource
    private SuperAdministratorService superAdministratorService;


    @PostMapping("/register")
    public R<Object> register(@RequestBody SuperAdministrator superAdministrator) {

        String register = superAdministratorService.register(superAdministrator);
        return R.success(register);
    }

    @GetMapping("/usernameIsRegister/{username}")
    public R<String> usernameIsRegister(@PathVariable("username") String username) {

        SuperAdministrator one = superAdministratorService.getOne(new LambdaQueryWrapper<SuperAdministrator>()
                .eq(SuperAdministrator::getUsername, username));

        if(ObjectUtil.isNotEmpty(one))
            return R.error("当前用户名已被注册，请换一个用户名");

        return R.success("ok");
    }

}
